package com.gitee.wsl.prism4j.languages

import com.gitee.wsl.prism4j.Prism4j
import com.gitee.wsl.prism4j.Prism4j.Companion.grammar
import com.gitee.wsl.prism4j.Prism4j.Companion.pattern
import com.gitee.wsl.prism4j.Prism4j.Companion.token
import com.gitee.wsl.prism4j.Prism4j.Pattern

@Suppress("unused")
object Prism_lua {
    fun create(prism4j: Prism4j): Prism4j.Grammar {
        return grammar(
            "lua",
            token("comment", pattern(Pattern.compile("^--(?:\\[(=*)\\[[\\s\\S]*?(?:\\]\\1\\]|$)|[^\\r\\n]*)"))),
            token(
                "string",
                pattern(Pattern.compile("^(?:\\\"(?:[^\\\"\\\\]|\\\\[\\s\\S])*(?:\\\"|$)|\\'(?:[^\\'\\\\]|\\\\[\\s\\S])*(?:\\'|$))"))
            ),
            token("operator", pattern(Pattern.compile("(?:::|[:|'])\\b[a-z][\\w*+!?-]*\\b", Pattern.CASE_INSENSITIVE))),
            token(
                "keyword",
                pattern(
                    Pattern.compile("^(?:and|break|do|else|elseif|end|false|for|function|if|in|local|nil|not|or|repeat|return|then|true|until|while)\\b"),
                    true
                )
            ),
            token("boolean", pattern(Pattern.compile("\\b(?:true|false|nil)\\b"))),
            token("number", pattern(Pattern.compile("\\b[0-9A-Fa-f]+\\b"))),
            token("punctuation", pattern(Pattern.compile("^[^\\w\\t\\n\\r \\xA0][^\\w\\n\\r \\xA0\\\"\\'\\-\\+=]*")))
        )
    }
}
